package com.example.xymarket.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.widget.ListView;
import android.widget.Toast;

import com.example.xymarket.adapter.OrderAdapter;
import com.example.xymarket.common.MyHandler;
import com.example.xymarket.myView.StatusBar;
import com.example.xymarket.httpUtil.OrderService;
import com.example.xymarket.R;
import com.example.xymarket.po.Order;

import java.util.List;

public class OrderActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        MyHandler myHandler=new MyHandler(this,handler);
        OrderService orderService=new OrderService(myHandler);
        StatusBar.setStatusBarColor(this,StatusBar.yellow);
        orderService.getOrder();
        listView=(ListView) findViewById(R.id.ll1);
    }

    public ListView listView;
    public OrderAdapter orderAdapter;

    @SuppressLint("HandlerLeak")
    Handler handler=new Handler()
    {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what)
            {
                case 132:
                {
                    List<Order> list= (List<Order>) msg.obj;
                    orderAdapter=new OrderAdapter(list,getApplicationContext(),this);
                    listView.setAdapter(orderAdapter);
                    break;
                }
            }
        }
    };

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
            Intent intent=new Intent(getApplicationContext(),MineActivity.class);
            startActivity(intent);
            overridePendingTransition(0, 0);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}